<template>
  <div>
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-set-default
      show-search-result
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @change-area="changeArea"
    />
  </div>
</template>

<script>
import { areaList } from "@vant/area-data";
import { incAddress } from "@/api";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      areaCode: "",
    };
  },
  methods: {
    // 获取完整地址编码
    changeArea(value) {
      this.areaCode = value.map((item) => item.code).join("-");
    },
    async onSave(value) {
      value.country = value.county;
      value.areaCode = this.areaCode;
      console.log(value);
      let data = await incAddress(value);
      let { status, message } = data;
      if (!status) {
        this.$router.back();
      }
      this.$toast(message);
    },
  },
};
</script>
